import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LENOVO
 * Date: 2024-08-06
 * Time: 16:26
 */
//杨辉三角

public class LeetCode {
    public static List<List<Integer>> generate(int numRows) {
        List<Integer> list0 = new ArrayList<>();
        list0.add(1);
        List<List<Integer>> ret = new ArrayList<>();
        ret.add(list0);
        for (int i = 1; i < numRows; i++) {
            //首元素
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            //中间元素
            List<Integer> preRow = ret.get(i -1);
            for (int j = 1; j < i; j++) {
                int val1 = preRow.get(j);
                int val2 = preRow.get(j - 1);
                curRow.add(val1 + val2);
            }
            //尾元素
            curRow.add(1);
            ret.add(curRow);
        }
        return ret;
    }

    public static void main(String[] args) {

    }
}
